<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>留言板</title>

    <!-- Bootstrap core CSS -->
    <link href="./Tpl/css/bootstrap.min.css" rel="stylesheet">

    <style type="text/css">
    

    </style>

  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          
          <a class="navbar-brand" href="#">首页</a>
          <!-- <span class="navbar-brand " data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo" style="cursor: pointer;">留言</button> -->
          

        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <div class="navbar-form navbar-right">
            <!-- <div class="form-group">
              <input type="text" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control">
            </div> -->
            <button type="button" class="btn btn-success " data-toggle="modal" data-target="#login" data-whatever="@mdo">登录</button>
            <button type="button" class="btn btn-primary " data-toggle="modal" data-target="#signUp" data-whatever="@mdo">注册</button>
            <!-- <button type="button" class="btn btn-primary " data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">留言</button> -->
          </div>
        </div><!--/.navbar-collapse -->
      </div>
    </nav>

    <!-- Main jumbotron for a primary marketing message or call to action -->




    <div class="container" style="padding-top:100px;">

      


    <!-- 留言颜色 -->
    <?php $color = ['alert-success','alert-info',' alert-warning','alert-danger']; ?>


      <!-- Example row of columns -->
      <!-- 分页 -->    
      <div class="row">
        <nav aria-label="..." >
          <ul class="pagination" >
            <!-- 上一页 -->
            <?php if($page>1){ ?>
            <li><a href="./index.php?page=<?php echo $page-1; ?>" aria-label="Previous"><span aria-hidden="true">«</span></a></li>
            <?php } ?>
            <!-- 页码 -->
            <?php 
            if ($page<=3) {
              $start=1;
            }else if($page>=$pages-2){
              $start=$pages-4;
            }else{
              $start=$page-2;
            }
            if ($page>=$pages-2) {
              $end=$pages;
            }elseif ($page<=3) {
              $end=5;
            }else{
              $end=$page+2;
            }

             ?>

            <?php for ($i=$start; $i<= $end; $i++){ ?> 
            <li class="<?php if($page==$i){echo "active";} ?>"><a href="./index.php?page=<?php echo $i; ?>"><?php echo $i; ?> <span class="sr-only">(current)</span></a></li>
           <?php } ?>
            <!-- 下一页 -->
            <?php if($page<$pages){ ?>
            <li><a href="./index.php?page=<?php echo $page+1; ?>" aria-label="Next"><span aria-hidden="true">»</span></a></li>
            <?php } ?>
         </ul>
       </nav>
        <!-- 循环输出留言 -->
        <?php foreach ($data as $k => $row): ?>

          
          <div style="line-height:40px" class="alert <?php echo $color[array_rand($color)]; ?>" role="alert">
            <strong><?php if(isset($row['addressee'])){echo $row['addressee'].':';} ?></strong> <?php echo $row['content'] ?>（<?php echo Ftime($row['ctime']) ?>）
            <!-- <div style="float:right">
              <a href="./del.php?id=<?php echo $k; ?>" class="btn btn-danger">删除</a>
              <a href="./edit.php?id=<?php echo $k; ?>" class="btn btn-info">修改</a>
            </div> -->
          </div>
          
        <?php endforeach ?>
      </div>
      

      <hr>

      <footer>
        <!-- <p>&copy; 2016 Company, Inc.</p> -->
      </footer>
    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>


<!-- 留言 -->
<!--     <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">New message</h4>
      </div>
      <div class="modal-body">
        <form action="./add.php" method="post" id="formadd">
          <div class="form-group">
            <label for="recipient-name" class="control-label">Recipient:</label>
            <input type="text" class="form-control" id="recipient-name" name="username">
          </div>
          <div class="form-group">
            <label for="message-text" class="control-label">Message:</label>
            <textarea class="form-control" id="message-text" name="content"></textarea>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" id="sendMessage">Send message</button>
      </div>
    </div>
  </div>
</div> -->
<!-- 注册 -->
<div class="modal fade" id="signUp" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">注册</h4>
      </div>
      <div class="modal-body">
        <form action="./signUp.php" method="post" id="signUpBox">
          <div class="form-group">
            <label for="recipient-name" class="control-label">用户名</label>
            <input type="text" class="signUpCheck form-control" id="username" name="username">
          </div>
          <div class="form-group">
            <label for="recipient-name" class="control-label">邮箱</label>
            <input type="text" class="signUpCheck form-control" id="email" name="email">
          </div>
          <div class="form-group">
            <label for="message-text" class="control-label">密码</label>
            <input type="password" class="signUpCheck form-control" id="password" name="password">
          </div>
          <div class="form-group">
            <label for="message-text" class="control-label">确认密码</label>
            <input type="password" class="form-control" id="passwordConfirm" name="passwordConfirm">
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" id="signUpSubmit" >注册</button>
      </div>
    </div>
  </div>
</div>

<!-- 登录 -->
<div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">登录</h4>
      </div>
      <div class="modal-body">
        <form action="./login.php" method="post" id="loginBox">
          <div class="form-group">
            <label for="recipient-name" class="control-label">帐号</label>
            <input type="text" class="form-control" id="account" name="account">
          </div>
          <div class="form-group">
            <label for="message-text" class="control-label">密码</label>
            <input type="password" class="form-control" id="password" name="password">
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-success" id="loginSubmit">登录</button>
      </div>
    </div>
  </div>
</div>
<!-- 登录结束 -->

<script type="text/javascript">
  
$(function  () {
    // $('#sendMessage').click(function(event) {
    //   alert('999')
    //     $('#formadd').submit();
    // });
    $('#signUpSubmit').click(function(event) {
        $('#signUpBox').submit();
        var username = $('#username').val();
        var email=$('#email').val();
        var password=$('#password').val();
        var passwordConfirm=$('#passwordConfirm').val();
        $.ajax({
          url: './signUp.php',
          type: 'POST',
          dataType: 'json',
          data: {'username':username,'email':email,'password':password,'passwordConfirm':passwordConfirm},
        })
        .done(function(data) {
          console.log("success");
          console.log(data);
        })
        .fail(function() {
          console.log("error");
        })   
    });
    $('#loginSubmit').click(function(event) {
        $('#loginBox').submit();
    });
    $('.signUpCheck').blur(function(event) {
        var name=$(this).attr('name');
        var data=$(this).val();
        that = $(this);
        // alert(name)
        $.ajax({
          url: './signupCheck.php',
          type: 'POST',
          dataType: 'json',
          data: {name:name,value:data},
        })
        .done(function() {
          
        })
        .fail(function() {
          console.log("error");
        })
    });
})
</script>
  </body>
</html>
